//
//  UIView+Extension.swift
//  CMDB
//
//  Created by 曹桂祥 on 17/4/6.
//  Copyright © 2017年 CMDB. All rights reserved.
//
import UIKit

//MARK: 构造方法
extension UIView{
    //有frame
    class func getInstnce(frame:CGRect) -> Self {
        return self.init(frame:frame)
    }
    
    //无frame
    class func getInstance() -> Self{
        return self.init()
    }
}


private var delegateKey : String = "mdelegateKey"
private var dataKey : String = "dataKey"

extension UIView {
    
    weak var mDelegate : CMDBBaseViewDelegate?{
        set{
            objc_setAssociatedObject(self, &delegateKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_ASSIGN)
        }
        get{
            return (objc_getAssociatedObject(self, &delegateKey) as? CMDBBaseViewDelegate)!
        }
    }
    
    weak var data : AnyObject?{
        set{
            objc_setAssociatedObject(self, &dataKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_ASSIGN)
        }
        
        get{
            return objc_getAssociatedObject(self, &dataKey)
        }
        
    }
    
}

extension UIView : CMDBBaseViewDelegate{
    
    func onItemClickType(itemClickType: String?, data: AnyObject?, indexPath: NSIndexPath?) {
        mDelegate?.onItemClickType!(itemClickType, data: data, indexPath: indexPath)
    }
    
    func update(data: AnyObject?) {
        
    }
}

extension UIView {
    
    internal func configOwnSubviews() {
        
        
    }
    internal func addOwnSubviews() {
        
        
    }
    
    internal func buildSubViews(){
        
    }
}

extension UIView {
    // 初始化属性
    internal func setUp() {
        
        backgroundColor = UIColor.clearColor()
        
    }
}



